/* ===================================================================
 * File: 
 *		st7735.h
 *
 * Description:
 *		Function and macros declarations for ST7735 driver.
 *
 * Device:
 *		ST7735 LCD Driver
 *		Freescale FRDM-KL25Z platform
 *
 * Software:
 *		Keil uVision4
 *
 * Author:
 *		Krzysztof Blazewicz (blazewicz.krzysztof@gmail.com)
 *
 * Date:
 *		19.05.2013
 * ===================================================================*/

#ifndef ST7735_H_
#define ST7735_H_ 

#include <mkl25z4.h>
#include "color.h"

// Driver Commands
#define ST7735_NOP 0x00
#define ST7735_SWRESET 0x01
#define ST7735_RDDID 0x04
#define ST7735_RDDST 0x09
#define ST7735_RDDPM 0x0A
#define ST7735_RDDMADCTL 0x0B
#define ST7735_RDDCOLMOD 0x0C
#define ST7735_RDDIM 0x0D
#define ST7735_RDDSM 0x0E
#define ST7735_SLPIN 0x10
#define ST7735_SLPOUT 0x11
#define ST7735_PTLON 0x12
#define ST7735_NORON 0x13
#define ST7735_INVOFF 0x20
#define ST7735_INVON 0x21
#define ST7735_GAMSET 0x26
#define ST7735_DISPOFF 0x28
#define ST7735_DISPON 0x29
#define ST7735_CASET 0x2A
#define ST7735_RASET 0x2B
#define ST7735_RAMWR 0x2C
#define ST7735_RAMRD 0x2E
#define ST7735_PTLAR 0x30
#define ST7735_TEOFF 0x34
#define ST7735_TEON 0x35
#define ST7735_MADCTL 0x36
#define ST7735_IDMOFF 0x38
#define ST7735_IDMON 0x39
#define ST7735_COLMOD 0x3A
#define ST7735_RDID1 0xDA
#define ST7735_RDID2 0xDB
#define ST7735_RDID3 0xDC

#define ST7735_FRMCTR1 0xB1
#define ST7735_FRMCTR2 0xB2
#define ST7735_FRMCTR3 0xB3
#define ST7735_INVCTR 0xB4
#define ST7735_DISSET 0xB6
#define ST7735_PWCTR1 0xC0
#define ST7735_PWCTR2 0xC1
#define ST7735_PWCTR3 0xC2
#define ST7735_PWCTR4 0xC3
#define ST7735_PWCTR5 0xC4
#define ST7735_VMCTR1 0xC5
#define ST7735_VMOFCTR 0xC7
#define ST7735_WRID2 0xD1
#define ST7735_WRID3 0xD2
#define ST7735_PWCTR6 0xFC
#define ST7735_NVCTR1 0xD9
#define ST7735_NVCTR2 0xDE
#define ST7735_NVCTR3 0xDF
#define ST7735_GAMCTRP1 0xE0
#define ST7735_GAMCTRN1 0xE1
#define ST7735_EXTCTRL 0xF0
#define ST7735_VCOM4L 0xFF

#define A0_LOW() FPTE->PCOR |= (1UL<<5)
#define A0_HIGH() FPTE->PSOR |= (1UL<<5)
#define RST_LOW() FPTE->PCOR |= (1UL<<20)
#define RST_HIGH() FPTE->PSOR |= (1UL<<20)

/* debug only
void GPIO_Config(void);
void SPI_Config(void);
uint8_t SPI_Transfer(uint8_t);
void ST7735_WritePixel(uint16_t);
//uint16_t ST7735_ReadPixel(void);
void ST7735_WriteCommand(uint8_t, uint8_t, ...);
*/

/* misc. */
void ST7735_Init(void);
void ST7735_SetAddrWindow(uint8_t, uint8_t, uint8_t, uint8_t);
void drawPixel(uint8_t, uint8_t, uint16_t);
void drawChar(uint8_t, uint8_t, char, uint16_t);
void drawString(uint8_t, uint8_t, char *, uint16_t);

/* shapes */
void drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t);
void drawRectangle(uint8_t, uint8_t, uint8_t, uint8_t, uint16_t);
void fillRectangle(uint8_t, uint8_t, uint8_t, uint8_t, uint16_t);
void drawCircle(int16_t, int16_t, int16_t, uint16_t);
void fillCircle(int16_t, int16_t, int16_t, uint16_t);
void drawPolygon(uint8_t, uint8_t *, uint8_t *, uint16_t);
void fillPolygon(uint8_t, uint8_t *, uint8_t *, uint16_t);
void drawTriangle(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t);
void fillTriangle(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t);

/* freescale logo */
void drawFreescaleLogo(void);

#endif
